//
//  TownTableViewController.m
//  09-UITableViewHomeWork
//
//  Created by 曹曹 on 16/7/26.
//  Copyright © 2016年 曹曹. All rights reserved.
//

#import "TownTableViewController.h"
#import "Town.h"

#define kTableViewResuse @"reuseIdentifier"

@interface TownTableViewController ()

@end

@implementation TownTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _townArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kTableViewResuse];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:kTableViewResuse];
    }
    Town *town = [_townArray objectAtIndex:indexPath.row];
    NSArray *tempArray = [town.name componentsSeparatedByString:@" "];
    cell.textLabel.text = tempArray[4];
    cell.detailTextLabel.text = tempArray.lastObject;
    return cell;
}
@end
